﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace JobbJakt
{
    public class EncryptionClass
    {
        public static string EncryptString(string ClearText)
        {

            byte[] clearTextBytes = Encoding.UTF8.GetBytes(ClearText);

            System.Security.Cryptography.SymmetricAlgorithm rijn = SymmetricAlgorithm.Create();

            var memoryStream = new MemoryStream();
            byte[] rgbIV = Encoding.ASCII.GetBytes("oaknblddjamhvpkn");
            byte[] key = Encoding.ASCII.GetBytes("xvuxibcxkarayfmivhoaomtnvpejbjoo");
            var cs = new CryptoStream(memoryStream, rijn.CreateEncryptor(key, rgbIV),
            CryptoStreamMode.Write);

            cs.Write(clearTextBytes, 0, clearTextBytes.Length);

            cs.Close();

            return Convert.ToBase64String(memoryStream.ToArray());
        }

        public static string DecryptString(string EncryptedText)
        {
            byte[] encryptedTextBytes = Convert.FromBase64String(EncryptedText);

            var memoryStream = new MemoryStream();

            SymmetricAlgorithm rijn = SymmetricAlgorithm.Create();


            byte[] rgbIV = Encoding.ASCII.GetBytes("oaknblddjamhvpkn");
            byte[] key = Encoding.ASCII.GetBytes("xvuxibcxkarayfmivhoaomtnvpejbjoo");

            var cs = new CryptoStream(memoryStream, rijn.CreateDecryptor(key, rgbIV),
            CryptoStreamMode.Write);

            cs.Write(encryptedTextBytes, 0, encryptedTextBytes.Length);

            cs.Close();

            return Encoding.UTF8.GetString(memoryStream.ToArray());

        }
    }
}
